﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ado.netproject
{
    class Program
    {
        static void Main(string[] args)
        {
            //ADO.NET数据库
            var conString = "server=LAPTOP-47B7TGQ4\\SQLEXPRESS;database=Person;uid=sa;pwd=2113144056";

            SqlConnection sqlConnection = new SqlConnection(conString);

            sqlConnection.Open();

            var cmdString = "select * from Users";

            SqlCommand command = new SqlCommand(cmdString, sqlConnection);

            var reade = command.ExecuteReader();

            // Console.WriteLine("{0}\t{1}", "111","222");

            Console.WriteLine("{0}\t{1}\t{2}","Id","用户名称:","用户密码");

            while (reade.Read())
            {
                Console.WriteLine( "{0}\t{1}\t{2}",reade["Id"],reade["Salary"],reade["Name"]);
            }
            sqlConnection.Close();

            DataTable table = new DataTable();

            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, conString);

            dataAdapter.Fill(table);

            Console.WriteLine();

            foreach(DataRow row in table.Rows)
            {
                Console.WriteLine(row["Id"]);
            }
        }
    }
}
